/*
 *  RSA.h
 *  TubeTruck
 *
 *  Created by Aeturnum on 5/22/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#pragma once

#include "Encryptor.h"
#include "Signer.h"
#include "Signable.h"
#include "Encryptable.h"
#include "util.h"

#include <vector>
#include <openssl/rsa.h>
#include <openssl/err.h>
#include <openssl/sha.h>
#include <openssl/objects.h>
#include <cstdlib>
#include <time.h>
#include <assert.h>

namespace TTP {
   namespace Crypt {
      class RSA : public EKey, public SKey {
      protected:
         ::RSA* mKeys;
         uint32_t mIdHash;
         
         void makeHash();
         void generateKeys(int, unsigned long);
      public:
         
         enum {RSAKeyLength = 128};
         
         RSA();
         RSA(int);
         ~RSA();
         RSA(const RSA&);
         
         std::vector<byte> getPublicKey();
         std::vector<byte> getPrivateKey();
         uint32_t getIdHash();
         void setPublicKey(std::vector<byte>&);
         void setPrivateKey(std::vector<byte>&);
         
         std::vector<byte> encrypt(const std::vector<byte>&);
         std::vector<byte> decrypt(const std::vector<byte>&);
         void encrypt(Encryptable&);
         void decrypt(Encryptable&);
         void sign(Signable&);
         bool verify(Signable&);
      };
   }
}